package _defer

import "fmt"

func Defer() []int {

	array := []int{1, 2, 3, 4, 5}

	var newArray = make([]int, 5, 5)
	for i := range array {
		newArray[i] = array[i]
		defer fmt.Println(array[i])
	}

	return newArray
}

func defer_order() {
	defer func() {
		println("defer 1")
	}()

	defer func() {
		println("defer 2")
	}()

	println("defer by order")
}

func name(a int) (b int) {
	defer func() {
		a++
		b++
	}()
	// 先赋值，再执行defer函数
	a++
	return a
}

func anonymous(a int) int {
	var b int
	defer func() {
		a++
		b++
	}()
	a++
	b = a
	return b
}
